class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.o: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

k = A("k")
b = B("b")
g = B("g")
h = B("h")
l = A("l")

k.z = h
k.o = l
b.t = h
g.t = b
h.t = b
l.z = h
l.o = k
assert b.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.o: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

k = A("k")
b = B("b")
g = B("g")
h = B("h")
l = A("l")

k.z = h
k.o = l
b.t = h
g.t = b
h.t = b
l.z = h
l.o = k
assert b.t.t.t.txt == "h"