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

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

g = A("g")
e = B("e")
k = B("k")
l = B("l")
m = B("m")
n = A("n")
b = B("b")

g.z = k
g.t = n
e.x = g
k.x = g
l.x = g
m.x = n
n.z = k
n.t = g
b.x = n
assert k.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.t: A = None
        self.txt = txt

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

g = A("g")
e = B("e")
k = B("k")
l = B("l")
m = B("m")
n = A("n")
b = B("b")

g.z = k
g.t = n
e.x = g
k.x = g
l.x = g
m.x = n
n.z = k
n.t = g
b.x = n
assert k.x.z.x.txt == "g"