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

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

d = A("d")
k = B("k")
j = A("j")
n = B("n")
g = A("g")
f = B("f")
a = B("a")
c = A("c")

d.r = f
k.x = c
j.r = n
n.x = d
g.r = a
f.x = c
a.x = d
c.r = f
assert k.x.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

d = A("d")
k = B("k")
j = A("j")
n = B("n")
g = A("g")
f = B("f")
a = B("a")
c = A("c")

d.r = f
k.x = c
j.r = n
n.x = d
g.r = a
f.x = c
a.x = d
c.r = f
assert k.x.r.x.r.txt == "f"